package com.t3.anistory
{
	import com.t3.client.T3Client;
	import com.t3.display.Thumbnail;
	import com.t3.fx.DraggableObject;
	import com.t3.tuio.TUIOCursor;
	import com.t3.tuio.TUIOEvent;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	public class StoryPage extends DraggableObject
	{
		[Embed(source='/thumbnail.swf')]
		private static var mc_Thumbnail:Class;
		private static var indices:uint = 0;
		
		private var _text:Thumbnail;
		private var _drawing:Thumbnail;
		private var _anistory:AniStory;
		private var _index:uint;
		private var _activeBorder:Shape;
		
		private var _mcThumb:Sprite;
		
		public function StoryPage( story:AniStory = null ):void
		{
			super( new Rectangle( 0,0,0,0 ) );
			
			_anistory = story != null ? story : new AniStory();
			_index = indices++;
			_anistory = anistory;
			_text = _anistory.notebook.thumbnail;
			_drawing = anistory.sketchbook.thumbnail;
			
			_text.y = _drawing.y = 6;
			
			_mcThumb = new mc_Thumbnail(); 
			_mcThumb.height = _drawing.height + 10;
			
			_activeBorder = new Shape();
			_activeBorder.graphics.lineStyle( 5, 0x3333FF );
			_activeBorder.graphics.drawRect( -4, -1, _mcThumb.width + 7, _mcThumb.height + 9 );
			
			this.addChild( _mcThumb );
			this.addChild( _text );
			this.addChild( _drawing );
			
			_text.x = 4;
			_drawing.x = _text.width + 7;
		}
		
		public function get anistory():AniStory
		{
			return _anistory;
		}
		
		public function get index():uint
		{
			return _index;
		}
		
		public function set active( active:Boolean ):void
		{
			if( active )
			{
				addChild( _activeBorder );
			}
			else if( contains( _activeBorder ) )
			{
				removeChild( _activeBorder );
			}
		}
		
		protected override function repaint():void {}
		
		public override function startDragging( cursor:TUIOCursor ):DraggableObject
		{
			T3Client.waslijn.save();
			T3Client.waslijn.currentPage = this;
					
			return this;
		}
		
		public override function stopDragging( event:TUIOEvent ):void {}
	}
}